//src/main/java/com/cuit/blog/service/ArticleService.java
package com.cuit.blog.service;
import com.cuit.blog.dao.ArticleRespository;
import com.cuit.blog.entity.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import java.util.List;import org.springframework.data.domain.Page;

@Service

public class ArticleService {
    @Autowired
    ArticleRespository articleRepository;

    public List<Article> findAll(){
        return articleRepository.findAll();
    }
    public void save(Article article) {
        articleRepository.save(article);
    }
    public Article findById(int id) {
        return articleRepository.findById(id).orElse(null);
    }

    public void deleteById(int id) {
        articleRepository.deleteById(id);
    }
    public Page<Article> findAllByPage(int pageIndex, int pageSize) {
        return articleRepository.findAll(PageRequest.of(pageIndex, pageSize));
    }
}
